package com.strive.filter;

import com.strive.common.model.base.RequestModel;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.UUID;

/**
 * @description:
 * @author: bingcun.chen
 * @Date: 2022/3/2 15:02
 * @Version 1.0
 */
public class RequestIdFilter extends OncePerRequestFilter {
    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
        String requestId = UUID.randomUUID().toString().replaceAll("-","");
        RequestModel requestModel = new RequestModel();
        requestModel.setRequestId(requestId);
        RequestModel.setRequestModel(requestModel);
        filterChain.doFilter(request,response);
    }
}
